package com.yitongmao.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.yitongmao.bean.HomeListBean;
import com.yitongmao.yitmfruit.R;

import java.util.List;

/*
* 作者：梁伟航 on 2017/7/17 17:57
* 类的用途：
*/
public class HomeRedaiAdapter extends BaseAdapter{
    private Context context;
    private List<HomeListBean.GoodsListBean> goodsList;
    public HomeRedaiAdapter(Context context, List<HomeListBean.GoodsListBean> goodsList) {
        this.context=context;
        this.goodsList=goodsList;
    }
    @Override
    public int getCount() {
        return goodsList.size();
    }

    @Override
    public Object getItem(int position) {
        return goodsList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        if (convertView == null) {
            viewHolder = new ViewHolder();
            convertView=View.inflate(context, R.layout.homeredaiitem,null);
            viewHolder.homelistTitle = (TextView) convertView.findViewById(R.id.homelistTitle);
            viewHolder.homelistBody = (TextView) convertView.findViewById(R.id.homelistBody);
            viewHolder.homelistprice = (TextView) convertView.findViewById(R.id.homelistprice);
            viewHolder.homelistgouwu = (ImageView) convertView.findViewById(R.id.homelistgouwu);
            viewHolder.homelistimage = (ImageView) convertView.findViewById(R.id.homelistimage);
            convertView.setTag(viewHolder);//绑定ViewHolder对象
        }else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        viewHolder.homelistTitle.setText(goodsList.get(position).subtitle);
        viewHolder.homelistBody.setText(goodsList.get(position).describes);
        viewHolder.homelistprice.setText(""+goodsList.get(position).retailPrice);
        Glide.with(context).load(goodsList.get(position).thumb).into(viewHolder.homelistimage);
        return convertView;
    }
    class ViewHolder {

        public TextView homelistTitle;
        public TextView homelistBody;
        public TextView homelistprice;
        public ImageView homelistgouwu;
        public ImageView homelistimage;
    }
}
